package reflect;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;

/**
 * @Author Zhouchb
 * @Create 2022-04-2022/4/3 :22:55
 * @Description
 */
interface Star{
    public void word();
}
class SuperStar implements Star{
    public void word(){
        System.out.println("我是大明星");
    }
}
class MyInvocationHandle implements InvocationHandler {
    private Object object;

    public void setObject(Object obj) {
        this.object = obj;
    }

    public Object getProxyInstance(){
        return Proxy.newProxyInstance(this.getClass().getClassLoader(), object.getClass().getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是代理类："+proxy.getClass());
        System.out.println("我是被代理类："+object.getClass());
        Object result = method.invoke(object,args);
        return result;
    }
}
class DynamicProxy{
    public static void main(String[] args) {
        SuperStar superStar = new SuperStar();
        MyInvocationHandle handle = new MyInvocationHandle();
        handle.setObject(superStar);
        Star starProxy = (Star) handle.getProxyInstance();
        starProxy.word();
    }
}
//快排
class kuaipai{
    public static void main(String[] args) {
        int[] arr = new int[]{6,5,3,9,2,3};sort(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));
    }
    public static void sort(int[] arr,int l,int r){
        if (l>=r){
            return;
        }
        int mid = partition(arr,l,r);
        sort(arr,l,mid-1);
        sort(arr,mid+1,r);
    }
    public static int partition(int[] arr,int l,int r){
        int key = arr[l];
        while (l<r){
            while (arr[r]>=key&&l<r){
                r--;
            }
            arr[l]=arr[r];
            while (arr[l]<=key&&l<r){
                l++;
            }
            arr[r]=arr[l];
        }
        arr[l]=key;
        return l;
    }

}
